package com.kstech.ks_gaz01.data;

import android.graphics.Rect;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * author: lenovo
 * created on: 2023/12/19 13:44
 * description: 给gridLayoutManger 分隔间隔
 */
public class GridSpaceItemDecoration extends RecyclerView.ItemDecoration {
    private int mSpanCount;//横条目数量
    private int mRowSpacing;//行间距
    private int mColumnSpacing;// 列间距

    /**
//     * @param spanCount     列数
     * @param rowSpacing    行间距
     * @param columnSpacing 列间距
     */
    public GridSpaceItemDecoration(int rowSpacing, int columnSpacing) {
//        this.mSpanCount = spanCount;
        this.mRowSpacing = rowSpacing;
        this.mColumnSpacing = columnSpacing;
    }

    @Override
    public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
//        int position = parent.getChildAdapterPosition(view); // 获取view 在adapter中的位置。
//        int column = position % mSpanCount; // view 所在的列

        outRect.left = mColumnSpacing;
        outRect.right = mColumnSpacing;
        outRect.top = mRowSpacing; // item top
        outRect.bottom = mRowSpacing;
    }
}
